//$URL: http://dasding.googlecode.com/svn/branches/testzeugs/data/dao/mongoDB/src/main/java/de/piratech/dasding/data/database/mongo/ActionCategoryDataImpl.java $
//$Id: ActionCategoryDataImpl.java 90 2012-11-20 18:42:49Z amuthmann@gmail.com $
/*
 * Copyright 2012 Piratech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.piratech.dasding.data.database.mongo;

import com.mongodb.DB;
import de.piratech.dasding.data.ActionCategory;
import de.piratech.dasding.data.database.ActionCategoryData;
import de.piratech.dasding.data.database.DatabaseException;
import java.util.List;

/**
 */
public class ActionCategoryDataImpl extends AbstractMongoDB<ActionCategory> implements ActionCategoryData {

  public ActionCategoryDataImpl(DB pDB) {
    super(pDB, ActionCategory.class, COLLECTIONS.ACTIONCATEGORY_COLLECTION);
  }

  @Override
  public ActionCategory createActionCategory(ActionCategory pActionCategory) {
    return getDBCollection().insert(pActionCategory).getSavedObject();
  }

  @Override
  public ActionCategory getActionCategory(String pId) {
    return getDBCollection().findOneById(pId);
  }

  @Override
  public void updateActionCategory(ActionCategory pActionCategory) {
    getDBCollection().updateById(pActionCategory.getId(), pActionCategory);
  }

  @Override
  public void deleteActionCategory(ActionCategory pActionCategory) throws DatabaseException {
    getDBCollection().removeById(pActionCategory.getId());
  }

  @Override
  public List<ActionCategory> getCategories() {
    return getDBCollection().find().toArray();
  }

  @Override
  public List<ActionCategory> getVerifiedCategories() {
    return findByVerified(true);
  }

  @Override
  public List<ActionCategory> getNotVerifiedCategories() {
    return findByVerified(false);
  }

  public List<ActionCategory> findByVerified(boolean pVerified) {
    return getDBCollection().find().is("verified", pVerified).toArray();
  }
}
